package cn.lyjuan.first.netty.demo._5_netty_heartbeat.client.handler;

import cn.lyjuan.first.netty._4_netty_serialize.msg.MyMessage;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.net.InetSocketAddress;

public class ClientHandler extends SimpleChannelInboundHandler<MyMessage>
{
    private static Logger log = LogManager.getLogger(ClientHandler.class);

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, MyMessage msg) throws Exception
    {
        InetSocketAddress host = (InetSocketAddress) ctx.channel().remoteAddress();
        log.info("client receive from " + host.getHostName() + ":" + host.getPort() + ": " + msg);
    }
}
